<!DOCTYPE html>
<html lang="en">
<script src="js/jquery-3.4.1.min.js"></script>
<script>
    $(function (){
        //给电话添加blur事件
        $("input[name='phone']").blur(function () {
            var name = $("input[name='name']").val();
            var idNumber = $("input[name='idNumber']").val();
            var phone = $("input[name='phone']").val();
            //验证电话号码是否合规
            let reg = /^1[356789]\d{9}$/;
            if (!reg.test(phone)){
                //电话不合法
                $("#phone").html("请输入正确的电话号码");
                return;
            }
            $.get("openaccount.servlet?method=secondAccount",function (data) {
                $("input[name='secondAccountNumber']").val(data);
            })
        });
        //给身份证号添加blur事件
        $("#idNumber").blur(function () {
            var idNumber = $("input[name='idNumber']").val();
            //验证身份证号号码是否合规(第二代身份证18位)
            let idNu = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
            if (!idNu.test(idNumber)){
                //身份证号不合法
                $("#idNumber").html("请输入正确的身份证号");
                return;
            }
        });

        //给提交按钮添加点击事件
        $("#open").click(function () {
            var name = $("input[name='name']").val();
            var idNumber = $("input[name='idNumber']").val();
            var phone = $("input[name='phone']").val();
            var secondAccountNumber = $("input[name='secondAccountNumber']").val();
            var password1=$("input[name='password1']").val();
            var password2=$("input[name='password2']").val();
            if (!name){
                alert("姓名必填！");
                $("input[name = 'name']").focus();
                return;
            }
            if (!idNumber){
                alert("身份证号必填！");
                $("input[name='idNumber']").focus();
                return;
            }
            if (!phone){
                alert("手机号必填");
                $("input[name='phone']").focus();
                return;
            }
            if (!password2){
                alert("支付密码必填！")
                $("input[name='password2']").focus();
                return;
            }
            if (!password1){
                alert("支付密码必填！")
                $("input[name='password1']").focus();
                return;
            }
            if (password1 == password2){
            }else {
                alert("支付密码不一致！");
                return;
            }
            //给提交按钮添加身份证号的验证
            // $("#idNumber").blur(function () {
            //     var idNumber = $("input[name='idNumber']").val();
            //     //验证身份证号号码是否合规(第二代身份证18位)
            //     let idNu = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
            //     if (!idNu.test(idNumber)){
            //         //身份证号不合法
            //         alert("身份证号不合法");
            //         $("#idNumber").html("请输入正确的身份证号");
            //         return;
            //     }
            // });
            $.get("openaccount.servlet?method=open&name="+name+'&idNumber='+idNumber+'&phone='+phone+'&secondAccountNumber='+secondAccountNumber+'&password1='+password1,function (data) {
                if (data == 'y') {
                    alert("开户成功，即将跳转到首页去绑卡");
                    //跳转到首页
                    window.location.href="account_index.jsp";
                }else if (data == 'n') {
                    alert("开户失败");
                    //跳转到当前页,重新开户
                    window.location.href="openaccount.html";
                } else {
                    alert("开户手机号与注册手机号必须一致！");
                    //跳转到当前页,重新开户
                    window.location.href="openaccount.html";
                }
            })
        });
    });
</script>
<head>
    <title>开户</title>
</head>
<body>

<br/>
<br/>
<form>
    <table width="60%" align="center" border="1">
        <tr>
            <td align="center"><h1>开户</h1></td>
        </tr>
        <tr align="center">
            <td><h3>请输入您的姓名：<input type="text"  name="name" id="name" style="width:300px;height:30px;font-size: large" /></h3></td>
        </tr>
        <tr align="center">
            <td><h3>请输入身份证号：<input type="text" name="idNumber" id="idNumber" style="width: 300px;height: 30px;font-size: large" /></h3></td>
        </tr>
        <tr align="center">
            <td><h3>请输入手机号：&nbsp;&nbsp;<input type="text" name="phone" id="phone" style="width: 300px;height: 30px;font-size: large" /></h3></td>
        </tr>
        <tr align="center">
            <td><h3>您的二类账户为：<input type="text" name="secondAccountNumber" id="secondAccountNumber" style="width: 300px;height: 30px;font-size: large" readonly /></h3></td>
        </tr>
        <tr align="center">
            <td><h3>请设置支付密码：<input type="password" name="password1" id="password1" style="width: 300px;height: 30px;font-size: large" /></h3></td>
        </tr>
        <tr align="center">
            <td><h3>再次输入支付密码：<input type="password" name="password2" style="width: 300px;height: 30px;font-size: large" /></h3></td>
        </tr>
        <tr align="center">
            <td><h3><input type="button" value="开户" id="open" style="width: 300px;height: 30px;font-size: large" /></h3></td>
        </tr>
        <tr align="center">
            <td><h3><input type="reset" value="重置" style="width: 300px;height: 30px;font-size: large" /></h3></td>
        </tr>
    </table>
</form>
</body>
</html>

